home *** CD-ROM | disk | FTP | other *** search
/ Apple WWDC 1996 / WWDC96_1996 (CD).toast / Technology Materials / QuickTime VR / MacOS / QuickDraw™ 3D 1.0.6F4 SDK / Development / 3DMF parser / 1.0 version / MF3DPC / MFBINUTL.H < prev    next >
Encoding:
C/C++ Source or Header  |  1995-11-07  |  2.0 KB  |  63 lines  |  [TEXT/dosa]

  1. #ifndef    MF3D_BINARYUTILS_H
  2. #define    MF3D_BINARYUTILS_H
  3. /*==============================================================================
  4.  *
  5.  *    File:        MFBINUTL.H
  6.  *
  7.  *    Function:    Binary swap utilities
  8.  *
  9.  *    Version:    Metafile:    Version 1.0 3DMF files
  10.  *                Package:    Release #2 of this code
  11.  *
  12.  *    Author(s):    Rick Wong (RWW), Duet Development Corp.
  13.  *                John Kelly (JRK), Duet Development Corp.
  14.  *
  15.  *    Copyright:    (c) 1995 by Apple Computer, Inc., all rights reserved.
  16.  *
  17.  *    Change History (most recent first):
  18.  *        FB7_JRK    Pragma macros
  19.  *        Fabio    Changed file name to 8 characters
  20.  *        F2H_RWW    File created.
  21.  *==============================================================================
  22.  */
  23. #if defined(applec) || defined(__MWERKS__) || defined(THINK_C)
  24. #pragma once
  25. #endif
  26.  
  27. #include "MFASSERT.H"
  28.  
  29. #define    MF3D_Swap4(a, b)    (*(long *)&(a)) ^= (*(long *)&(b));                \
  30.                             (*(long *)&(b)) ^= (*(long *)&(a));                \
  31.                             (*(long *)&(a)) ^= (*(long *)&(b))
  32.  
  33. #define    MF3D_ByteSwap2(n)    (*(long*)&(n)) =                                \
  34.                                 (((*(long*)&(n)) & 0xFF00) >> 8) |            \
  35.                                 (((*(long*)&(n)) & 0x00FF) << 8)
  36.  
  37. #define    MF3D_ByteSwap4(n)    (*(long*)&(n)) =                                \
  38.                                 (((*(long*)&(n)) & 0xFF000000) >> 24)    |    \
  39.                                 (((*(long*)&(n)) & 0x00FF0000) >> 8)    |    \
  40.                                 (((*(long*)&(n)) & 0x0000FF00) << 8)    |    \
  41.                                 (((*(long*)&(n)) & 0x000000FF) << 24)
  42.  
  43. #define    MF3D_ByteSwap8(n)    MF3D_ByteSwap4(*(long *)&(n));                    \
  44.                             MF3D_Swap4(*(long *)&(n), *(((long *)&(n))+1));    \
  45.                             MF3D_ByteSwap4(*(long *)&(n));
  46.  
  47. #define    MF3D_ByteSwap(bytes, n)        MFASSERT(bytes == 8 || bytes == 4 ||    \
  48.                                             bytes == 2);                    \
  49.                                     if (bytes == 8)                            \
  50.                                     {    MF3D_ByteSwap8(n);                    \
  51.                                     }                                        \
  52.                                     else if (bytes == 4)                    \
  53.                                     {    MF3D_ByteSwap4(n);                    \
  54.                                     }                                        \
  55.                                     else if (bytes == 2)                    \
  56.                                     {    MF3D_ByteSwap2(n);                    \
  57.                                     }                                        \
  58.                                     else                                    \
  59.                                     {    MFASSERT(bytes);                    \
  60.                                     }
  61.  
  62. #endif
  63.